﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
//using System.Xml.XmlDocument;
using System.IO;


namespace MBSPL.App_Code
{
    public static class Utility
    {
        public static Dictionary<string, string> getSeatAvailability(string xmlString)
        {
            Dictionary<string, string> dctSeatAvailability = new Dictionary<string, string>();
            ////string xmlString = "<seatlayout><seat status='Available'>A1</seat><seat status='Available'>A2</seat><seat status='Available'>A3</seat><seat status='Available'>A4</seat><seat status='Available'>A5</seat><seat status='Available'>A6</seat><seat status='Available'>A7</seat><seat status='Available'>A8</seat></seatlayout>";
            //XmlDocument xmlDoc = new XmlDocument();
            //xmlDoc.Load(new StringReader(xmlString));
            //var seatInfo=from node in xmlDoc.Descendants("seatlayout")
            //          select new {
            //          status=node.Attribute("status").Value,
            //          seatno=node.Value
            //          };
            //foreach (var seat in seatInfo)
            //{
            //    dctSeatAvailability.Add(seat.seatno, seat.status);
            //}
            return dctSeatAvailability;
        }

        public static string setseatStatusBooked(string xmlString,string seatno)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(new StringReader(xmlString));
            XmlNode node = xmlDoc.SelectSingleNode("seatlayout/seat/" + seatno);
            node.Attributes["status"].Value = "Booked";
            xmlDoc.Save(xmlString);

            return xmlString;
        
        }
    }
}